package com.sanjiahantang.youjiarole.module.login.views.impl;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.webkit.WebView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.module.common.utils.CommonModelUtils;
import com.sanjiahantang.youjiarole.module.login.presenters.LoginPresenter;
import com.sanjiahantang.youjiarole.module.login.views.LoginView;

/**
 * Created by zy on 2018/3/26.
 */

public class RegisterProtocolActivity extends BaseMvpActivity<LoginView,LoginPresenter> implements LoginView, View.OnClickListener {

    private WebView webView;
    private View btnSubmit,btnCancel;


    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public LoginPresenter initPresenter() {
        return new LoginPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_register_protocol);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("注册协议");

        webView = (WebView) findViewById(R.id.webView);
        btnSubmit = findViewById(R.id.btnSubmit);
        btnCancel = findViewById(R.id.btnCancel);
        btnSubmit.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
        findViewById(R.id.fl_Left).setOnClickListener(this);
    }

    @Override
    public void initData() {
        CommonModelUtils.findConfigCode($this, CommonModelUtils.CONFIG_CODE_AGREE, new OnLoadListener() {
            @Override
            public void onLoad(Object content) {
                if (content != null){
                    webView.loadDataWithBaseURL(null, (String) content, "text/html", "UTF-8", null);
                }else{
                    webView.loadDataWithBaseURL(null, "优家库注册协议，请同意", "text/html", "UTF-8", null);
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btnSubmit:
                setResult(RESULT_OK);
                finish();
                break;
            case R.id.btnCancel:
                setResult(RESULT_FIRST_USER);
            case  R.id.fl_Left:
                finish();
                break;
        }
    }

    public static void startActivity(Activity context,int requestCode){
        context.startActivityForResult(new Intent(context,RegisterProtocolActivity.class),requestCode);
    }
}
